<template>
  <div class="app-container">
    <div style="overflow:hidden">
      <el-form style="float:left">
        <el-form-item label="手机号" label-width="60px" class="input">
          <el-input v-model="phoneNum" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="页面类型" :label-width="formLabelWidth" class="input">
           <el-select v-model="pointType" placeholder="请选择" clearable>
              <el-option
                v-for="item in typeArr"
                :key="item.value"
                :label="item.value"
                :value="item.name">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="时间查询" :label-width="formLabelWidth" class="input">
            <el-date-picker
              v-model="dateArr"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
        </el-form-item>
      </el-form>
      <el-button type="primary" icon="el-icon-search" style="float:left;margin-left:10px" @click="getList">查询</el-button>
    </div>
    <el-table :data="appData" border style="width: 100%">
       <el-table-column prop="userPhone"         label="用户手机号"         min-width="100"></el-table-column>
      <el-table-column prop="description"        label="页面"         min-width="100"></el-table-column>
      <!-- <el-table-column prop="recordDate"         label="日期"       min-width="110"></el-table-column> -->
      <el-table-column prop="num"                label="点击次数"       min-width="80"></el-table-column>
      <el-table-column prop="lastUpdated"        label="最后更新时间"       min-width="110"></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size">
      </el-pagination>
    </div>
  </div>  
</template>
<script>
import moment from 'moment'
import { pointList, typePoint } from 'api/appData'
export default {
  data() {
    return {
      appData: [],
      pageSize: 10,
      curPage: 1,
      size: 0,
      formLabelWidth: '100px',
      dateArr: [],
      phoneNum: '',
      typeArr: [],
      pointType: ''
    }
  },
  created() {
    this.getType()
    this.getList()
  },
  methods: {
    async getList() {
      const parm = {
        pageSize: this.pageSize,
        curPage: this.curPage - 1,
        userPhone: this.phoneNum,
        pointType: this.pointType
      }
      if (this.dateArr == null || this.dateArr.length === 0) {
        parm.startDay = ''
        parm.endDay = ''
      } else {
        parm.startDay = moment(this.dateArr[0]).format('YYYY-MM-DD')
        parm.endDay = moment(this.dateArr[1]).format('YYYY-MM-DD')
      }
      try {
        let back = await pointList(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.appData = back.result
          this.size = back.size
        } else {
          this.$alert(back.msg, '提示')
        }
      } catch (err) {
        this.$alert('出错了' + err, '提示')
      }
    },
    async getType() {
      try {
        let back = await typePoint()
        back = back.data
        if (back.resultCode === '200') {
          this.typeArr = back.result
        } else {
          this.$alert(back.msg, '提示')
        }
      } catch (err) {
        this.$alert('出错了' + err, '提示')
      }
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.curPage = val
      this.getList()
    }
  }
}
</script>
<style scoped>
  .block{
    float: right;
    margin-top:20px;
  }
  .input{
    float: left;
  }
</style>